home *** CD-ROM | disk | FTP | other *** search
/ Lattice ISP Synario Start… & ISP Encyclopedia 1997 / LATTICE Synario.iso / ispcode / gds / gasm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-03  |  28.6 KB  |  1,127 lines

  1. /***************************************************************************
  2.  
  3.   Copyright Lattice Semiconductor, Inc. (1992)
  4.  
  5.  
  6. ***************************************************************************/
  7. /***************************************************************************
  8.  
  9.    Program: gasm.c
  10.  
  11.    Purpose:
  12.    To assemble a source file for one of the ipsGDS devices into a JEDEC file.
  13.  
  14.    Usage:
  15.    gasm  sourcefile [JEDEC_filename]
  16.  
  17.    Usage is also available by calling the progam without any parameters, or
  18.    with less than two parameters.
  19.  
  20.    Revision History:
  21.  
  22. $Log: gasm.c_v $
  23. # Revision 1.1  1993/06/28  17:23:39  Mike_Lottridge
  24. # Initial revision
  25. #
  26.  
  27. ****************************************************************************/
  28.  
  29. #include <stdio.h>
  30. #include <ctype.h>
  31. #include <stdlib.h>
  32. #include <string.h>
  33. #include <dos.h>
  34.  
  35.  
  36. #define FALSE 0
  37. #define TRUE 1
  38. #define NEG 0
  39. #define POS 1
  40.  
  41. #define MAX_FUSES 219
  42. #define MAX_LINE_LENGTH 256
  43. #define TITLE_LENGTH 1024
  44. char *PROGRAM_NAME = "GASM";
  45.  
  46. typedef enum IO_TYPE { INPUT, OUT_INV, OUT_NONINV, OUT_0, OUT_1, UNUSED, NOT_IO};
  47. typedef enum LINE_TYPE { TITLE, DEVICE, COMMENT, PIN_DEF, UES_ASCII, UES_HEX, UES_BINARY, LINE_ERROR};
  48. typedef enum DEVICE_TYPE {ISPGDS22, ISPGDS18, ISPGDS14, ERROR};
  49.  
  50. typedef struct {
  51.       enum IO_TYPE io_type;
  52.       int input;
  53.       char bank;  /* bank and cell number always relates to ispGDS22 */
  54.       int  cell;
  55.       }PIN_TYPE;
  56.  
  57. /* Assign bank letters to each pin. Array index = pin #. 'pin 0' not used */
  58. char ispgds22_bank[] = "0AAA0AA0AAA0AAABBB0BB0BBB0BBB";
  59.  
  60. char ispgds18_bank[] = "0AAA0A0AA0AAABBB0B0BB0BBB";
  61.  
  62. char ispgds14_bank[] = "0AAA00A0AAABBB00B0BBB";
  63.  
  64.  
  65. /* Assign IO cell numbers to each pin. Array index = pin #. 'pin 0' not used */
  66. int ispgds22_cell[] =
  67. {
  68. -1,  0, 1, 2, -1, 3, 4, -1, 5, 6, 7, -1, 8, 9, 10,
  69.     10, 9, 8, -1, 7, 6, -1, 5, 4, 3, -1, 2, 1, 0
  70. };
  71. int ispgds18_cell[] =
  72. {
  73. -1,  0, 1, 2, -1, 3, -1, 6, 7, -1, 8, 9, 10,
  74.     10, 9, 8, -1, 7, -1, 4, 3, -1, 2, 1, 0
  75. };
  76. int ispgds14_cell[] =
  77. {
  78. -1,  0, 1, 2, -1, -1, 7, -1, 8, 9, 10,
  79.     10, 9, 8, -1, -1, 3, -1, 2, 1, 0
  80. };
  81.  
  82. PIN_TYPE pin[29]; /* 28 pins total, but 'pin 0' not used */
  83. FILE *source_file, *outfile, *outfile2;
  84. char *source_filename;
  85. char *root_filename;
  86.  
  87. int fuse[ MAX_FUSES ];
  88. int ues[32];
  89. char title[ TITLE_LENGTH ];
  90. enum DEVICE_TYPE device;
  91. int line_number; /* line number of source file */
  92.  
  93. /*  function prototypes */
  94. void main(int argc, char *argv[]);
  95. void read_source( void );
  96. void init(void);
  97. enum LINE_TYPE get_line_type(char *line);
  98. void get_title(char *line);
  99. void get_device(char *line);
  100. void get_pin_def(char *line);
  101. void get_ues_ascii( char *line);
  102. // void get_ues_hex( char *line);
  103. // void get_ues_binary( char *line);
  104. void line_error(int line_number, const char *errstr);
  105. void quit(const char *errstr);
  106. int equal( char *str1, const char *str2);
  107. void assemble(void);
  108. void write_jedec( FILE *jed_file);
  109. void calc_fuse_checksum( char *fuse_checksum);
  110. void write_doc( FILE *doc_file);
  111.  
  112.  
  113. /*************************************************************************
  114.   MAIN
  115. **************************************************************************/
  116.  
  117. void main(int argc, char *argv[])
  118. {
  119. int i;
  120. char *temp_filename, *temp_filename2;
  121.  
  122. printf(" %s: ispGDS Assembler \n", PROGRAM_NAME);
  123. printf("     copyright (c)1993 Lattice Semiconductor\n");
  124. printf("     Version 1.01 \n ");
  125.  
  126. if ( argc < 2 )
  127.    {
  128.    printf("\nUsage: %s sourcefile  [JEDEC_file] ", PROGRAM_NAME);
  129.    exit(0);
  130.    }
  131.  
  132. /* store the filename for later use */
  133. source_filename = (char *)calloc( strlen(argv[1]) +1, sizeof(char) );
  134. strcpy(source_filename, argv[1]);
  135.  
  136. root_filename =(char *)calloc( strlen(source_filename) +5, sizeof(char) );
  137. for(i=0;i<strlen(source_filename);i++)
  138. {
  139.   if(source_filename[i] == '.')
  140.     break;
  141.   root_filename[i] = source_filename[i];
  142. }
  143.  
  144. /* read the source file */
  145. source_file = fopen(argv[1],"r");
  146. if (source_file == NULL)
  147.    {
  148.    perror("\n ERROR OPENING SOURCE FILE: \n");
  149.    exit(0);
  150.    }
  151.  
  152. printf("\nReading Source file\n");
  153. read_source();
  154.  
  155. if(fclose(source_file) == EOF)
  156.   perror("\n Error Closing Source File: \n");
  157.  
  158.  
  159. /* generate the proper fuse settings */
  160. assemble();
  161.  
  162.  
  163. /* Write out the JEDEC file */
  164. if(argc>2)
  165.   outfile = fopen(argv[2],"w");
  166. else
  167. {
  168.   temp_filename = strdup(root_filename);
  169.   outfile = fopen( strcat(temp_filename, ".JED"), "w");
  170. }
  171. if(outfile == NULL)
  172.    {
  173.    perror("ERROR OPENING OUTPUT FILE: ");
  174.    exit(1);
  175.    }
  176.  
  177. write_jedec(outfile);
  178.  
  179. if(ferror(outfile) != 0)
  180. {
  181.  printf("Error writing JEDEC file \n");
  182.  clearerr(outfile);
  183.  printf("Error cleared\n");
  184. }
  185. else
  186.   printf("\nJEDEC file successfully written to disk\n");
  187.  
  188. if(fclose(outfile) == EOF)
  189.   perror("\n Error Closing JEDEC File: \n");
  190.  
  191.  
  192. /* Write out the Documentation file */
  193. if(argc>3)
  194.   outfile2 = fopen(argv[3],"w");
  195. else
  196. {
  197.   temp_filename2 = strdup(root_filename);
  198.   outfile2 = fopen( strcat(temp_filename2, ".DOC"), "w");
  199. }
  200. if(outfile2 == NULL)
  201.    {
  202.    perror("ERROR OPENING OUTPUT FILE: ");
  203.    exit(1);
  204.    }
  205.  
  206. write_doc(outfile2);
  207.  
  208. if(ferror(outfile2) != 0)
  209. {
  210.  printf("Error writing DOC file \n");
  211.  clearerr(outfile2);
  212.  printf("Error cleared\n");
  213. }
  214. else
  215.   printf("\nDOC file successfully written to disk\n");
  216.  
  217.  
  218. if(fclose(outfile2) == EOF)
  219.   perror("\n Error Closing DOC File: \n");
  220.  
  221.  
  222. exit(0);
  223. } /* main */
  224.  
  225. /*****************************************************************
  226. read_source()
  227.  
  228. reads the source file and stores all the data in data structures.
  229.  
  230. ******************************************************************/
  231.  
  232. void read_source()
  233. {
  234. char line[MAX_LINE_LENGTH];
  235. enum LINE_TYPE linetype;
  236.  
  237. /* intialize the global data structures */
  238. init();
  239.  
  240. /* read each line of the source file and process according to type */
  241.  
  242. while( fgets(line, MAX_LINE_LENGTH, source_file) != NULL )
  243. {
  244.   line_number++; /* initialized in init() */
  245.   linetype = get_line_type(line);
  246.  
  247.   switch (linetype)
  248.    {
  249.     case COMMENT:        break; /* ignore comments */
  250.  
  251.     case TITLE:          get_title(line);
  252.                          break;
  253.  
  254.     case DEVICE:         get_device(line);
  255.                          break;
  256.  
  257.     case PIN_DEF:        get_pin_def(line);
  258.                          break;
  259.  
  260.    case UES_ASCII:       get_ues_ascii(line);
  261.                          break;
  262.  
  263. //   case UES_HEX:         get_ues_hex(line);
  264. //                         break;
  265.  
  266. //   case UES_BINARY:      get_ues_binary(line);
  267. //                         break;
  268.  
  269.    case LINE_ERROR:      line_error(line_number, "Syntax Error");
  270.                          break; 
  271.    }
  272.  
  273. } /* while */
  274.  
  275. } /* read_source() */
  276.  
  277. /***********************************************************************
  278. init()
  279.  
  280. Initialize Global Data Structures
  281.  
  282. ************************************************************************/
  283. void init()
  284. {
  285. int i;
  286.  
  287.    for(i=0; i < 29; i++)
  288.    {
  289.      pin[i].io_type = UNUSED; /* default for unused pins */
  290.      pin[i].input = 0;
  291.    }
  292.  
  293.    for(i=0; i < 121; i++)    /* unused array bits are set to 1 */
  294.       fuse[i] = 1;
  295.    for(; i < MAX_FUSES; i++) /* arch and UES default to 0 */
  296.       fuse[i] = 0;
  297.  
  298.  
  299.    for(i=0;i<TITLE_LENGTH;i++)
  300.       title[i] = NULL;
  301.  
  302.    for(i=0;i<32;i++)
  303.       ues[i] = 0;
  304.  
  305.    line_number = 0;
  306.    device = ERROR;
  307.  
  308.  
  309. } /* init() */
  310.  
  311.  
  312. /**********************************************************************
  313. enum LINE_TYPE get_line_type(char *line)
  314.  
  315. Takes a line from the source file, checks the front portion of the
  316. line, looking for PIN, UES_xxx, TITLE, or DEVICE keywords.
  317.  
  318. ************************************************************************/
  319. enum LINE_TYPE get_line_type(char *line)
  320. {
  321. char token[20];
  322. int i, j, len;
  323.  
  324.   for(i=0;i<20;i++) token[i] = NULL; /* initialize token string */
  325.   len = strlen(line);
  326.  
  327.   for(i=0; i<len; i++)
  328.   {
  329.     if(line[i] != ' ') break; /* get past any spaces at the front of the line */
  330.   }
  331.   if( i==len) return(COMMENT); /* blank line, ignore, like comment */
  332.   if( line[i] == '\n') return(COMMENT); /* The line is blank */
  333.  
  334.   if( line[i] == '"') return(COMMENT); /* The whole line is a comment */
  335.  
  336.   j=0;
  337.   while( isalpha(line[i])|| (line[i]=='_') )
  338.   {
  339.     token[j] = toupper(line[i]); /* make it all upper case */
  340.     i++; j++;
  341.   }
  342.  
  343.   if(equal(token, "TITLE"))      return(TITLE);
  344.   if(equal(token, "DEVICE"))     return(DEVICE);
  345.   if(equal(token, "PIN"))        return(PIN_DEF);
  346.   if(equal(token, "UES_ASCII"))  return(UES_ASCII);
  347.   if(equal(token, "UES_HEX"))    return(UES_HEX);
  348.   if(equal(token, "UES_BINARY")) return(UES_BINARY);
  349.   /* default */
  350.   return(LINE_ERROR);
  351.  
  352. }  /* get_line_type */
  353.  
  354. /**********************************************************************
  355. get_title( char *line)
  356.  
  357. Takes a line from the source file, beginning with the keyword TITLE,
  358. extracts the text betweeen single quotes, and stores in the global
  359. structure 
  360.  
  361. ***********************************************************************/
  362.  
  363. void get_title( char *line)
  364. {
  365. int i,j,len;
  366.  
  367.   len = strlen(line);
  368.   for( i=0; i<len; i++)
  369.   {
  370.      if( line[i] == 39)  /* find the ' to start the TITLE block */
  371.        break;
  372.    }
  373.   /* if no single quote on line with Title, exit with error message */
  374.   if( (i==len) || (line[i]=='\n') )
  375.      line_error(line_number,"Could not find single quote to start Title section");
  376.  
  377.   /* if quote found, store Title block in a buffer */
  378.   i++;
  379.   for( j=0; j < TITLE_LENGTH; j++)
  380.   {
  381.     if( line[i] == 39) /* if single quote found */
  382.        break;
  383.     else
  384.     {
  385.        title[j] = line[i];
  386.        i++;
  387.        if(title[j] == '\n')
  388.        {
  389.          if( fgets(line, MAX_LINE_LENGTH, source_file) == NULL )
  390.            line_error(line_number,"Can't find ' to end TITLE block");
  391.          line_number++; /* if newline, increment line_number count*/
  392.          i = 0;         /* starting a new line */
  393.        }
  394.     }
  395.    }
  396.  
  397. } /* get_title */
  398.  
  399. /**********************************************************************
  400. get_device( char *line)
  401.  
  402. Takes a line from the source file, beginning with the keyword DEVICE,
  403. and extracts the device type, storing it in the device variable. This
  404. routine also stores the bank letter and IO cell numbers in the pin[]
  405. structure.
  406.  
  407. ***********************************************************************/
  408.  
  409. void get_device( char *line)
  410. {
  411. int i,j,len;
  412. char dev[256];
  413.  
  414.   len = strlen(line);
  415.   for( i=0; i<len; i++)
  416.   {
  417.      if( line[i] == '=')  /* find the =  */
  418.      break;
  419.   }
  420.   /* if no equal sign on line DEVICE, exit with error message */
  421.   if(i==len)
  422.   {
  423.     printf("\n Error on Line %d: Could not find equal sign for DEVICE statement\n", line_number);
  424.     exit(1);
  425.   }
  426.  
  427.   /* if = found, get the device type */
  428.   i++;
  429.   for(j=0 ; i < len; i++)
  430.   {
  431.     if( isalnum(line[i]) )
  432.     {
  433.       dev[j] = toupper(line[i]);
  434.       j++;
  435.     }
  436.   }
  437.   dev[j] = NULL; /* terminate the string */
  438.  
  439.   if( equal( dev, "ISPGDS22") ) device = ISPGDS22;
  440.   else if( equal( dev, "ISPGDS18") ) device = ISPGDS18;
  441.   else if( equal( dev, "ISPGDS14") ) device = ISPGDS14;
  442.   else
  443.      quit(" \nInvalid device type, or syntax error in DEVICE definition statement\n");
  444.  
  445.   /* Store bank and io cell info for each pin, specific to device type */
  446.   if(device == ISPGDS22)
  447.   {
  448.      for(i=1;i<29;i++)
  449.      {
  450.        pin[i].bank = ispgds22_bank[i];
  451.        pin[i].cell = ispgds22_cell[i];
  452.      }
  453.   }
  454.   if(device == ISPGDS18)
  455.   {
  456.      for(i=1;i<25;i++)
  457.      {
  458.        pin[i].bank = ispgds18_bank[i];
  459.        pin[i].cell = ispgds18_cell[i];
  460.      }
  461.   }
  462.   if(device == ISPGDS14)
  463.   {
  464.      for(i=1;i<21;i++)
  465.      {
  466.        pin[i].bank = ispgds14_bank[i];
  467.        pin[i].cell = ispgds14_cell[i];
  468.      }
  469.   }
  470.  
  471. } /* get_device */
  472.  
  473. /**********************************************************************
  474. get_pin_def( char *line)
  475.  
  476. Takes a line from the source file, beginning with the keyword PIN,
  477. and stores the pin assignments
  478.  
  479. ***********************************************************************/
  480.  
  481. void get_pin_def( char *line)
  482. {
  483. int i,j,k,len,left_side;
  484. int outpin, inpin;
  485. int outpin_polarity = POS;
  486. int found_equal_sign = FALSE;
  487. char  tempnum[20]; /* leave plenty of room for overruns, just in case */
  488. char temp_alpha[20];
  489. char input_type;
  490. int found_inpin = FALSE;
  491.  
  492.   for(i=0;i<20;i++)
  493.   {
  494.      tempnum[i] = 0; /* initialize array */
  495.      temp_alpha[i] = 0;
  496.    }
  497.  
  498.   len = strlen(line);
  499.  
  500. /* the presence of the PIN keyword has already been established, so */
  501. /* only look for the numbers and negations */
  502.   for(j=0, i=0; i<len; i++)
  503.   {
  504.      if( line[i] == '=')  /* only read the left side of the equation */
  505.      {
  506.        found_equal_sign = TRUE;
  507.        break;
  508.      }
  509.      if( line[i] == '!') /* get the polarity of the left side */
  510.        outpin_polarity = NEG;
  511.      if( isdigit(line[i]) )
  512.      {
  513.        tempnum[j] = line[i];
  514.        j++;
  515.      }
  516.   }
  517.   if(found_equal_sign != TRUE)
  518.     line_error(line_number," Syntax error in PIN definition \n");
  519.  
  520.   tempnum[j] = NULL; /* null terminate the tempnum string */
  521.   outpin = atoi(tempnum);
  522.   if( !valid_pin(outpin) )
  523.   {
  524.     printf("ERROR on line %d: Pin %d is not a valid I/O pin number", line_number, outpin);
  525.     exit(1);
  526.    }
  527.  
  528.   for(j=0, k=0; i<len; i++) /* keep the i value to point to right side of equation */
  529.   {
  530.      if( line[i] == '!') /* check for illegal polarity definition on right side */
  531.         line_error(line_number,"Negation not allowed on right side of equation ");
  532.      if( isdigit(line[i]) )
  533.      {
  534.        found_inpin = TRUE;
  535.        tempnum[j] = line[i];
  536.        j++;
  537.      }
  538.     if(isalpha(line[i]) )
  539.     {
  540.       temp_alpha[k] = toupper(line[i]);
  541.       k++;
  542.     }
  543.   }
  544.  
  545.   tempnum[j] = NULL; /* null terminate the tempnum string */
  546.   inpin = atoi(tempnum);
  547.   if( found_inpin)
  548.   {
  549.     if( !valid_pin(inpin) )
  550.     {
  551.        printf("ERROR on line %d: Pin %d is not a valid I/O pin number", line_number, inpin);
  552.        exit(1);
  553.     }
  554.   }
  555.   input_type = temp_alpha[0]; /* only the first letter is actually used */
  556.  
  557.   /* check if pin previously defined, and define output type */
  558.   if( pin[outpin].io_type != UNUSED)
  559.   {
  560.     printf("\nERROR on Line %d: PIN %d already been defined\n", line_number, outpin);
  561.     exit(1);
  562.   }
  563.   else if( input_type == 'P')      /* right side is PIN definition */
  564.   {
  565.     if( !((pin[inpin].io_type == INPUT) || (pin[inpin].io_type == UNUSED)) )
  566.     {
  567.       printf("\nERROR on Line %d: Pin %d has already been assigned as an output\n", line_number, inpin);
  568.       exit(1);
  569.     }
  570.  
  571.     pin[outpin].input = inpin; /* assign input pin to connect to */
  572.     pin[inpin].io_type = INPUT;
  573.  
  574.     if(outpin_polarity == NEG)
  575.         pin[outpin].io_type = OUT_INV;
  576.     else
  577.         pin[outpin].io_type = OUT_NONINV;
  578.   }
  579.   else if(input_type == 'L')              /* says LOW or LO */
  580.      pin[outpin].io_type = OUT_0;
  581.   else if(input_type == 'H')              /* says HIGH or HI */
  582.      pin[outpin].io_type = OUT_1;
  583.   else
  584.   {
  585.      printf("\nSyntax Error on Line %d\n", line_number);
  586.      exit(1);
  587.    }
  588.  
  589. } /* get_pin_def */
  590.  
  591. /**********************************************************************
  592. get_ues_ascii( char *line)
  593.  
  594. Takes a line from the source file, beginning with the keyword UES_ASCII,
  595. and extracts the UES string, storing it in the global variable. 
  596.  
  597. ***********************************************************************/
  598. void get_ues_ascii( char *line)
  599. {
  600. int i,j,len;
  601. char tmp;
  602. char ues_temp[MAX_LINE_LENGTH];
  603.  
  604.   for( i=0;i<MAX_LINE_LENGTH;i++)
  605.      ues_temp[i] = 0;
  606.  
  607.   len = strlen(line);
  608.   for( i=0; i<len; i++)
  609.   {
  610.      if( line[i] == '=')  /* find the =  */
  611.      break;
  612.   }
  613.   /* if no equal sign on line , exit with error message */
  614.   if(i==len)
  615.   {
  616.     printf("\n Error on Line %d: Could not find equal sign\n", line_number);
  617.     exit(1);
  618.   }
  619.  
  620.   /* if = found, get the UES  */
  621.   for(j=0 ; i < len; i++)
  622.   {
  623.     if( isalnum(line[i]) )
  624.     {
  625.       ues_temp[j] = toupper(line[i]);
  626.       j++;
  627.     }
  628.   }
  629.   for(i=0;i<4;i++)
  630.   {
  631.      tmp = ues_temp[i];
  632.      for(j=0;j<8;j++)
  633.      {
  634.        if( tmp & 0x80 ) /* high bit set */
  635.           ues[(i*8)+j] = 1;
  636.        else
  637.           ues[(i*8)+j] = 0;
  638.        tmp = tmp << 1;
  639.      }
  640.   }
  641.  
  642. } /* get_ues_ascii */
  643.  
  644.  
  645. /*********************************************************************
  646. int valid_pin(int pin)
  647.  
  648. Checks that the pin number specified is a valid I/O pin for the device
  649. specified
  650.  
  651. ***********************************************************************/
  652. int valid_pin(int pin)
  653. {
  654.   if(device == ERROR)
  655.   {
  656.      printf("\nERROR: Device not specified. DEVICE statement needed before equations\n");
  657.      exit(1);
  658.   }
  659.  
  660.  
  661.   if(device == ISPGDS22)
  662.   {
  663.      if( (pin >28) || (pin <1) )
  664.         return(FALSE);
  665.  
  666.      switch(pin)
  667.      {
  668.         case  4:        return(FALSE);
  669.         case  7:        return(FALSE);
  670.         case 11:        return(FALSE);
  671.         case 18:        return(FALSE);
  672.         case 21:        return(FALSE);
  673.         case 25:        return(FALSE);
  674.         default:        return(TRUE);
  675.       }
  676.   }
  677.   else if(device == ISPGDS18)
  678.   {
  679.      if( (pin >24) || (pin <1) )
  680.         return(FALSE);
  681.  
  682.      switch(pin)
  683.      {
  684.         case  4:        return(FALSE);
  685.         case  6:        return(FALSE);
  686.         case  9:        return(FALSE);
  687.         case 16:        return(FALSE);
  688.         case 18:        return(FALSE);
  689.         case 21:        return(FALSE);
  690.         default:        return(TRUE);
  691.       }
  692.   }
  693.   else if(device == ISPGDS14)
  694.   {
  695.     if( (pin >20) || (pin <1) )
  696.         return(FALSE);
  697.  
  698.      switch(pin)
  699.      {
  700.         case  4:        return(FALSE);
  701.         case  5:        return(FALSE);
  702.         case 7:         return(FALSE);
  703.         case 14:        return(FALSE);
  704.         case 15:        return(FALSE);
  705.         case 17:        return(FALSE);
  706.         default:        return(TRUE);
  707.       }
  708.    }
  709.    else
  710.    {
  711.      printf("\nERROR: Device not specified. Device must be specified before equations. \n");
  712.      exit(1);
  713.    }
  714.  
  715.  
  716. return(FALSE); /* shouldn't be reached */
  717.  
  718. } /* valid_pin */
  719.  
  720. /*********************************************************************
  721. void error_check()
  722.  
  723. Checks that the specified design can fit into the device.
  724. - each input/output pair must be in different banks
  725.  
  726. ***********************************************************************/
  727. void error_check()
  728. {
  729. int i;
  730.  
  731.   if(device == ISPGDS22)
  732.   {
  733.      for(i=1;i<29;i++)
  734.      {
  735.         if(pin[i].input != 0) /* input pin assigned to this output */
  736.         {
  737.            if( ispgds22_bank[i] == ispgds22_bank[ pin[i].input ])
  738.            {
  739.               printf("\nERROR: Output Pin %d and input pin %d must be in different banks\n",i,pin[i].input);
  740.               exit(1);
  741.             }
  742.          }
  743.       }
  744.     }
  745.   else if(device == ISPGDS18)
  746.   {
  747.      for(i=1;i<25;i++)
  748.      {
  749.         if(pin[i].input != 0) /* input pin assigned to this output */
  750.         {
  751.            if( ispgds18_bank[i] == ispgds18_bank[ pin[i].input ])
  752.            {
  753.               printf("\nERROR: Output Pin %d and input pin %d must be in different banks\n",i,pin[i].input);
  754.               exit(1);
  755.             }
  756.          }
  757.      }
  758.   }
  759.  
  760.   else if(device == ISPGDS14)
  761.   {
  762.      for(i=1;i<21;i++)
  763.      {
  764.         if(pin[i].input != 0) /* input pin assigned to this output */
  765.         {
  766.            if( ispgds14_bank[i] == ispgds14_bank[ pin[i].input ])
  767.            {
  768.               printf("\nERROR: Output Pin %d and input pin %d must be in different banks\n",i,pin[i].input);
  769.               exit(1);
  770.             }
  771.          }
  772.       }
  773.    }
  774.    else quit("\n Device not specified\n");
  775.  
  776. } /* error_check () */  
  777.  
  778.  
  779. /*********************************************************************
  780. void line_error(int line_number, const char *errstr)
  781.  
  782. prints out an error message, with a line number, and exits
  783.  
  784. ***********************************************************************/
  785.  
  786. void line_error(int line_number, const char *errstr)
  787. {
  788.  
  789. printf("\n ERROR on Line %d: %s \n", line_number, errstr);
  790. exit(1);
  791.  
  792. } /* line_error() */
  793.  
  794.  
  795. /*********************************************************************
  796. void quit(const char *errstr)
  797.  
  798. prints out an error message and terminates program
  799.  
  800.  
  801. ***********************************************************************/
  802.  
  803. void quit(const char *errstr)
  804. {
  805.  
  806. #ifdef DEBUG0
  807. show_error("in quit() ");
  808. #endif
  809.  
  810. printf("\n ERROR: %s \n", errstr);
  811. fcloseall();
  812. exit(1);
  813.  
  814. } /* quit() */
  815.  
  816.  
  817. /*********************************************************************
  818. int equal( char *str1, const char *str2)
  819.  
  820. compare two strings, and returns 1 if equal, or 0 if not;
  821.  
  822. ***********************************************************************/
  823.  
  824. int equal( char *str1, const char *str2)
  825. {
  826.  
  827. if( !strcmp( str1, str2) ) return(1);
  828. else return(0);
  829. }
  830.  
  831.  
  832.  
  833. /********************************************************************/
  834. /********************************************************************/
  835. /*                         OUTPUT ROUTINES                          */
  836. /********************************************************************/
  837. /********************************************************************/
  838.  
  839. /*********************************************************************
  840. void assemble()
  841.  
  842. Fills the fuse[] array with the proper fuse settings, which can
  843. then be used to generate the JEDEC map
  844.  
  845. ***********************************************************************/
  846. void assemble(void)
  847. {
  848. int i, arch_bit[3];
  849. int fuse_num;
  850. int number_of_pins;
  851.  
  852. /* fuse[] was initialized to all zeros in the init() function */
  853.  
  854.  if(device==ISPGDS22)
  855.     number_of_pins = 28;
  856.  if(device==ISPGDS18)
  857.     number_of_pins = 24;
  858.  if(device==ISPGDS14)
  859.     number_of_pins = 20;
  860.  
  861.  for(i=1;i<number_of_pins+1;i++)
  862.  {
  863.  
  864.     if(pin[i].input != 0) /* connection in array needed */
  865.     {
  866.        if(pin[i].bank == 'A')
  867.           fuse_num = 10 + (pin[i].cell * 11) - pin[ (pin[i].input) ].cell;
  868.        if(pin[i].bank == 'B')
  869.           fuse_num = (10 - pin[i].cell) + pin[ (pin[i].input) ].cell * 11;
  870.        fuse[ fuse_num ] = 0;
  871.     }
  872.  
  873. /* set ARCH bits */
  874.     switch(pin[i].io_type)
  875.     {
  876.        case INPUT:          arch_bit[0]=1;
  877.                             arch_bit[1]=0;
  878.                             arch_bit[2]=1;
  879.                             break;
  880.  
  881.        case OUT_NONINV:     arch_bit[0]=0;
  882.                             arch_bit[1]=1;
  883.                             arch_bit[2]=1;
  884.                             break;
  885.  
  886.        case OUT_INV:        arch_bit[0]=0;
  887.                             arch_bit[1]=0;
  888.                             arch_bit[2]=1;
  889.                             break;
  890.  
  891.        case OUT_1:          arch_bit[0]=0;
  892.                             arch_bit[1]=1;
  893.                             arch_bit[2]=0;
  894.                             break;
  895.  
  896.        case OUT_0:          arch_bit[0]=0;
  897.                             arch_bit[1]=0;
  898.                             arch_bit[2]=0;
  899.                             break;
  900.  
  901.        default:             arch_bit[0]=1;
  902.                             arch_bit[1]=1;
  903.                             arch_bit[2]=1;
  904.                             break;
  905.     } /* switch */
  906.  
  907.     if(pin[i].bank == 'A')
  908.     {
  909.        fuse[(174-pin[i].cell)] = arch_bit[0];
  910.        fuse[(196-pin[i].cell)] = arch_bit[1];
  911.        fuse[(218-pin[i].cell)] = arch_bit[2];
  912.     }
  913.     else if(pin[i].bank == 'B')
  914.     {
  915.        fuse[(153+pin[i].cell)] = arch_bit[0];
  916.        fuse[(175+pin[i].cell)] = arch_bit[1];
  917.        fuse[(197+pin[i].cell)] = arch_bit[2];
  918.     }
  919.  
  920.  }
  921.  
  922. /* Set UES bits */
  923.    fuse_num = 121;
  924.    for(i=0;i<32;i++, fuse_num++)
  925.       fuse[fuse_num] = ues[i];
  926.  
  927. }
  928.  
  929. /*********************************************************************
  930. void write_jedec()
  931.  
  932. ***********************************************************************/
  933.  
  934. void write_jedec(FILE *jed_file)
  935. {
  936. char fuse_checksum[5];
  937. char devstr[10], datestr[20];
  938. int len, i, j, qp;
  939. struct date d;
  940.  
  941.  
  942.   switch(device)
  943.   {
  944.      case ISPGDS22:      qp = 28;
  945.                          strcpy(devstr, "ispGDS22");
  946.                          break;
  947.      case ISPGDS18:      qp = 24;
  948.                          strcpy(devstr, "ispGDS18");
  949.                          break;
  950.      case ISPGDS14:      qp = 20;
  951.                          strcpy(devstr, "ispGDS14");
  952.                          break;
  953.   }
  954.  
  955.  
  956.   getdate(&d);
  957.   sprintf(datestr,"%d/%d/%d", d.da_mon, d.da_day, d.da_year);
  958.  
  959.   for(i=0;i<5;i++)
  960.      fuse_checksum[i] = NULL;
  961.   calc_fuse_checksum( (char *) fuse_checksum );
  962.  
  963.   fputc(2,jed_file); /* STX: start of transmission char */
  964.   fprintf(jed_file,"\nJEDEC file for %s , created on %s \n",devstr,datestr);
  965.   fprintf(jed_file,"Created by GASM v1.0\n\n");
  966.  
  967.   len = strlen(title);
  968.   for(i=0;i<len;i++)
  969.   {
  970.      fputc(title[i], jed_file);
  971.   }
  972.   fprintf(jed_file, "\n*\n");
  973.   fprintf(jed_file, "F0*\n");
  974.  
  975.   fprintf(jed_file, "QP%d* QF219*\n", qp);
  976.  
  977.   fprintf(jed_file, "L0000\n");
  978.   for(i=0;i<11;i++)
  979.   {
  980.      for(j=0;j<11;j++)
  981.      {
  982.         if( fuse[ (i*11 + j)] == 0)
  983.           fputc('0',jed_file);
  984.         else
  985.           fputc('1',jed_file);
  986.      }
  987.  
  988.      if(i!=10) fputc('\n',jed_file);
  989.  
  990.   }
  991.   fprintf(jed_file, "*\nL0121\n");
  992.   for(i=0;i<32;i++)
  993.   {
  994.      if( fuse[ i + 121] == 0)
  995.          fputc('0',jed_file);
  996.       else
  997.          fputc('1',jed_file);
  998.       }
  999.  
  1000.   fprintf(jed_file, "*\nL0153\n");
  1001.   for(i=0;i<22;i++)
  1002.   {
  1003.      if( fuse[ (i + 153)] == 0)
  1004.        fputc('0',jed_file);
  1005.      else
  1006.        fputc('1',jed_file);
  1007.    }
  1008.  
  1009.   fprintf(jed_file, "*\nL0175\n");
  1010.   for(i=0;i<22;i++)
  1011.   {
  1012.      if( fuse[ (i + 175)] == 0)
  1013.        fputc('0',jed_file);
  1014.      else
  1015.        fputc('1',jed_file);
  1016.    }
  1017.  
  1018.   fprintf(jed_file, "*\nL0197\n");
  1019.   for(i=0;i<22;i++)
  1020.   {
  1021.      if( fuse[ (i + 197)] == 0)
  1022.        fputc('0',jed_file);
  1023.      else
  1024.        fputc('1',jed_file);
  1025.    }
  1026.  
  1027. fprintf(jed_file, "*\n");
  1028.  
  1029. fprintf(jed_file, "C%s*\n",fuse_checksum);
  1030. fputc(3, jed_file); /* ETX: end of transmission char */
  1031. fprintf(jed_file, "0000\n");
  1032.  
  1033. } /* write_jedec */
  1034.  
  1035.  
  1036. /*********************************************************************
  1037. void calc_fuse_checksum()
  1038.  
  1039. calculate the 16-bit fuse checksum, and store in the passed array
  1040. ***********************************************************************/
  1041. void calc_fuse_checksum( char *fuse_checksum)
  1042. {
  1043. int i;
  1044. int checksum = 0;
  1045.  
  1046.   for(i=0;i<MAX_FUSES;i++)
  1047.   {
  1048.     if(fuse[i] == 1)
  1049.       checksum = checksum + ( 0x0001 << (i % 8) );
  1050.   }
  1051.  
  1052.   /* print checksum in hex to string to be returned */
  1053.    sprintf(fuse_checksum, "%X", checksum);
  1054.    printf("\nFuse Checksum = %X\n",checksum);
  1055.  
  1056. } /* calc_fuse_checksum */
  1057.  
  1058. /*********************************************************************
  1059. void write_doc()
  1060.  
  1061. ***********************************************************************/
  1062.  
  1063. void write_doc(FILE *doc_file)
  1064. {
  1065.  
  1066. int maxpins;
  1067. int i;
  1068. char devstr[10];
  1069.  
  1070.   for(i=0;i<10;i++)
  1071.     devstr[i]=NULL;
  1072.  
  1073.   switch(device)
  1074.   {
  1075.      case ISPGDS22:      maxpins = 28;
  1076.                          strcpy(devstr, "ispGDS22");
  1077.                          break;
  1078.      case ISPGDS18:      maxpins = 24;
  1079.                          strcpy(devstr, "ispGDS18");
  1080.                          break;
  1081.      case ISPGDS14:      maxpins = 20;
  1082.                          strcpy(devstr, "ispGDS14");
  1083.                          break;
  1084.   }
  1085.  
  1086. fprintf(doc_file,"Document file from GASM\nSource File: %s\n\n",source_filename);
  1087. fprintf(doc_file,"Device: %s\n\n",devstr);
  1088.  
  1089. fprintf(doc_file,"EQUATIONS\n");
  1090. for(i=1; i<=maxpins; i++)
  1091. {
  1092.   if(pin[i].io_type == OUT_0)
  1093.      fprintf(doc_file," PIN %d = LOW \n", i);
  1094.   else if(pin[i].io_type == OUT_1)
  1095.      fprintf(doc_file," PIN %d = HIGH \n", i);
  1096.   else if(pin[i].io_type == OUT_INV)
  1097.      fprintf(doc_file,"!PIN %d = PIN %d \n", i,pin[i].input);
  1098.   else if(pin[i].io_type == OUT_NONINV)
  1099.      fprintf(doc_file," PIN %d = PIN %d \n", i,pin[i].input);
  1100. }
  1101.  
  1102.  
  1103. /* *************
  1104. fprintf(doc_file,"PIN DEFINITIONS\N");
  1105. for(i=1; i<maxpins; i++)
  1106. {
  1107.   if(pin[i].io_type == NOT_IO)
  1108.      fprintf(doc_file," PIN %d is not an I/O pin \n", i);
  1109.   else if(pin[i].io_type == UNUSED)
  1110.      fprintf(doc_file," PIN %d is an unused I/O pin \n", i);
  1111.   else if(pin[i].io_type == INPUT)
  1112.      fprintf(doc_file," PIN %d is an input pin \n", i);
  1113.   else if(pin[i].io_type == OUT_0)
  1114.      fprintf(doc_file," PIN %d is an output pin, fixed to a TTL low \n", i);
  1115.   else if(pin[i].io_type == OUT_1)
  1116.      fprintf(doc_file," PIN %d is an output pin, fixed to a TTL high \n", i);
  1117.   else if(pin[i].io_type == OUT_INV)
  1118.      fprintf(doc_file," PIN %d is an output pin, with an inverted output \n", i);
  1119.   else if(pin[i].io_type == OUT_NONINV)
  1120.      fprintf(doc_file," PIN %d is an output pin \n", i);
  1121. }
  1122. ************** */
  1123.  
  1124.  
  1125. } /* write_doc */
  1126.  
  1127.